package com.study.springbootsecurity.handler;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;

/**
 * @Description: TODO
 * @author: Huangjianyun
 * @date: 2025-06-03 18:50
 */
@Slf4j
@Component
public class BaseMetaDataHandler implements MetaObjectHandler {


    /**
     * 插入自动填充字段
     * @param metaObject
     */
    @Override
    public void insertFill(MetaObject metaObject) {
        this.setFieldValByName("createTime", LocalDateTime.now(), metaObject);
        this.setFieldValByName("updateTime", LocalDateTime.now(), metaObject);
        //this.setFieldValByName("isDelete", 0, metaObject);
        log.info("come to insert fill .........");
    }

    /**
     * 更新字段填充字段
     * @param metaObject
     */
    @Override
    public void updateFill(MetaObject metaObject) {
        this.setFieldValByName("updateTime", LocalDateTime.now(), metaObject);
        log.info("come to update fill .......");
    }
}
